<?php

date_default_timezone_set('America/Recife');
session_start();
header('Content-Type: text/html; charset=utf-8');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');

require '../config.php';
require '../inc/db.php';
require '../inc/functions.php';
require '../inc/config.php';
require_once '../inc/changes.php';
require_once '../inc/config_dao.php';
require_once '../inc/netcontrol_ctl.php';
require_once '../inc/user_dao.php';
require_once '../inc/contract_dao.php';
require_once '../inc/client_dao.php';

$config = config::get_instance();
$client_dao = new client_dao();

$uri = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

if ($client = $client_dao->auth(get('client_username'))) {
	$client_dao->activate($client->client_id);
	$refresh = '<meta http-equiv="refresh" content="2;url='.$_POST['client_login_uri'].'">';
	$content = 'Você esta sendo redirecionado para: <a href="'.$_POST['client_login_uri'].'">'.$_POST['client_login_uri'].'</a>';
	include('template.php');
	iptables_refresh(false);
} else {
	$content = '
		<form action="http://'.$config->ip.':'.$config->cp_port.'" method="post">
			<input type="hidden" name="client_login_uri" value="'.$uri.'"/>
			<table>
				<tr>
					<th><label for="client_username">Usuario</label></th>
					<th><label for="client_password">Senha</label></th>
				</tr>
				<tr>
					<td><input type="text" id="client_username" name="client_username" value=""/></td>
					<td><input type="password" id="client_username" name="client_password" value=""/></td>
				</tr>
			</table>
			<button type="submit">Login</button>
		</form>
		';
		include('template.php');
}

?>
